package editor.cn;

//You own a Goal Parser that can interpret a string command. The command consist
//s of an alphabet of "G", "()" and/or "(al)" in some order. The Goal Parser will 
//interpret "G" as the string "G", "()" as the string "o", and "(al)" as the strin
//g "al". The interpreted strings are then concatenated in the original order. 
//
// Given the string command, return the Goal Parser's interpretation of command.
// 
//
// 
// Example 1: 
//
// 
//Input: command = "G()(al)"
//Output: "Goal"
//Explanation: The Goal Parser interprets the command as follows:
//G -> G
//() -> o
//(al) -> al
//The final concatenated result is "Goal".
// 
//
// Example 2: 
//
// 
//Input: command = "G()()()()(al)"
//Output: "Gooooal"
// 
//
// Example 3: 
//
// 
//Input: command = "(al)G(al)()()G"
//Output: "alGalooG"
// 
//
// 
// Constraints: 
//
// 
// 1 <= command.length <= 100 
// command consists of "G", "()", and/or "(al)" in some order. 
// 
// Related Topics 字符串 
// 👍 1 👎 0

public class GoalParserInterpretation{
    public static void main(String[] args) {
        Solution solution = new GoalParserInterpretation().new Solution();
        System.out.println(solution.interpret("G()(al)"));
    }

//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public String interpret(String command) {
        if ("".equals(command) || command == null) {
            return command;
        }
        char[] chars = command.toCharArray();
        char[] results = new char[chars.length];
        int index = 0;
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == 'G') {
                results[index++] = 'G';
            } else if (chars[i] == '(' & chars[i + 1] == ')') {
                results[index++] = 'o';
                i++;
                continue;
            } else {
                results[index++] = 'a';
                results[index++] = 'l';
                i += 3;
                continue;
            }
        }
        char[] temp = new char[index];
        for (int i = 0; i < index; i++) {
            temp[i] = results[i];
        }
        return new String(temp);
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}